var gulp = require('gulp');
var jade = require('gulp-jade');
var sass = require('gulp-sass');

var postcss      = require('gulp-postcss');
var sourcemaps   = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');


var sourcemaps = require('gulp-sourcemaps');
var minifyCss = require('gulp-minify-css');
var plumber = require('gulp-plumber');


var beep = require('beepbeep');


function errorHandler(err) {
    beep(2);
    console.error(err.toString());
}

gulp.task('test-sass', [], function () {
    gulp.src('test/*/**.scss')
        .pipe(plumber({errorHandler: errorHandler}))
        .pipe(sass())
        .pipe(minifyCss({compatibility: 'ie8'}))
        .pipe(sourcemaps.init())
        .pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] }) ]))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('dist'));
});

gulp.task('test-jade', [], function () {
    gulp.src('test/*/**.jade')
        .pipe(plumber({errorHandler: errorHandler}))
        .pipe(jade())
        .pipe(gulp.dest('dist'));
});


gulp.task('watch', ['default'], function () {
    gulp.watch('test/**/**.scss', ['test-sass']);
    gulp.watch('test/**/**.jade', ['test-jade']);
})

gulp.task('default', ['test-sass', 'test-jade']);

